//
//  CoolUnitySceneviewController.m
//  Unity-iPhone
//
//  Created by wencun on 4/3/15.
//
//

#import "CoolUnitySceneViewController.h"
#import "GoodByeViewController.h"
#include "UI/UnityViewControllerBase.h"
#include "UnityAppController+ViewHandling.h"
#import "MyViewInit.h"

@interface CoolUnitySceneViewController ()

@end

@implementation CoolUnitySceneViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.view addSubview:GetAppController().unityView];
    
    GetAppController().unityView.frame = self.view.frame;
    
    UILabel *text = [[UILabel alloc] initWithFrame:CGRectMake(40, 50, 300, 40)];
    text.text = @"欢迎进入Unity界面！(IOS)";
    text.textAlignment = NSTextAlignmentCenter;
    text.backgroundColor = [UIColor greenColor];
    [self.view addSubview:text];
    
    UITextField *tv = [[UITextField alloc] initWithFrame:CGRectMake(40, 100, 300, 40)];
    tv.textAlignment = NSTextAlignmentCenter;
    tv.layer.borderWidth = 1;
    tv.layer.cornerRadius = 3;
    [tv setPlaceholder:@"请键入文字..."];
    tv.tag = 101;
    [self.view addSubview:tv];
    
    UIButton *btnNext = [UIButton buttonWithType:UIButtonTypeSystem];
    [btnNext setTitle:@"点我可以修改CUBE中的文字(IOS)" forState:UIControlStateNormal];
    btnNext.frame = CGRectMake(40, 150, 300, 44);
    btnNext.backgroundColor = [UIColor whiteColor];
    btnNext.layer.borderWidth = 1;
    btnNext.layer.cornerRadius = 3;
    [self.view addSubview:btnNext];
    
    [btnNext addTarget:self action:@selector(goToLastScene:) forControlEvents:UIControlEventTouchUpInside];

    
    UIButton *recevied = [UIButton buttonWithType:UIButtonTypeSystem];
    [recevied setTitle:@"点我可以进入到另外一个IOS界面哦！(IOS)" forState:UIControlStateNormal];
    recevied.frame = CGRectMake(40, 450, 300, 44);
    recevied.backgroundColor = [UIColor whiteColor];
    recevied.layer.borderWidth = 1;
    recevied.layer.cornerRadius = 3;
    //    btnNext.center = CGPointMake(self.view.bounds.size.height / 2, self.view.bounds.size.width / 2);
    [self.view addSubview:recevied];
    
    [recevied addTarget:self action:@selector(recevied:) forControlEvents:UIControlEventTouchUpInside];
}

#pragma mark - Private methods
- (void)goToLastScene:(id)sender {
//    NSLog(@"[CoolUnitySceneVC] Go to the last scene");
    NSString *text = ((UITextField *)[self.view viewWithTag:101]).text;
    if ([text isEqualToString:@""]) {
        text = @"还没有给我一个名字哦！";
    }
    [MyViewInit setEnabled:text];
}

- (void)show:(id)sender{
    [MyViewInit setEnabled:@"show"];
}

- (void)recevied:(id)sender{
        GoodByeViewController *goodByeVC = [[GoodByeViewController alloc] initWithNibName:nil bundle:nil];
        [self.navigationController pushViewController:goodByeVC animated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
